package controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "LoginServlet", value = "/LoginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("UTF-8");




        String userName = request.getParameter("username");
        String password = request.getParameter("password");


        //模拟登录业务  在数据库查询用户名和密码存在 ，跳转到系统后台，不存在重新登录
        if(userName.equals("admin") && password.equals("123456"))
        {
            request.setAttribute("userName",userName);
            request.getRequestDispatcher("/BServlet").forward(request,response);
        }

        // 1.页面跳转 重定向
        // 2. 服务器内部： Servlet 之间跳转，处理不了时转发给能处理的Servlet，
        //    请求转发是连续 -> 同一个人 一个是请求对象
        //    数据共享 作用
        //  存取数据 :四种 Application   request    session cookie


    }
}
